<?php
	if ( ! $this->installed ) :
		$url = get_option('siteurl') . '/wp-admin/admin.php?page=smowtion_options';
		echo '<div class="wrap"><h2>Administrar Anuncios</h2>';
		echo  sprintf('<p>Antes de gestionar tus anuncios, debes ingresar tu <a href="%s">smowtion_section</a>.</p>', $url);
		echo '</div><!--.wrap-->';
	else : 
?>
<div class="wrap">

	<?php if (is_array($this->ads) && count($this->ads) > 0 ) : //if we have ads ?>
	
	<h2>Administrar Anuncios</h2>

	<form method="post" action="">
	
	<div class="tablenav">
		<div class="alignleft">
			<input value="Delete" name="delete_ads" class="button-secondary delete" type="submit" />
		</div>
		<br class="clear">
	</div>
		
	<table style="margin:1em auto;" class="widefat">
		<thead>
			<tr>
				<th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
				<th scope="col" class="manage-column" style="text-align:center;">ID</th>
				<th scope="col" class="manage-column">Nombre</th>
				<th scope="col" class="manage-column">Formato</th>
				<th scope="col" class="manage-column">Ubicación</th>
				<th scope="col" class="manage-column">Alineación</th>
				<th scope="col" class="manage-column">Publicación</th>
				<th scope="col" class="manage-column">Acciones</th>
			</tr>	
		</thead>		
		<tbody>
			<?php foreach ($this->ads as $k=>$ad) : ?>
			<tr <?=($k%2)?'class="alternate"':''?> valign="middle">
				<th scope="row" class="check-column"><input name="delete[]" value="<?=$ad->id?>" type="checkbox"></th>
				<td style="text-align:center;"><?=$ad->id?></td>
				<td><?=$ad->name?></td>
				<td><?=$this->options['format'][$ad->format]?></td>
				<td><?=$this->options['location'][$ad->location]?></td>
				<td><?=$this->options['align'][$ad->align]?></td>
				<td><?=$this->options['olderthan'][$ad->olderthan]?></td>
				<td><a href="<?=$_SERVER['REQUEST_URI']?>&smowtion_ad_id=<?=$ad->id?>">editar</a></td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
		
	</form>	
	
	<?php endif; ?>
		
	
	<h2>Nuevo Anuncio</h2>

	<form method="post" action="">
	<table class="form-table">
		<tbody>
			<tr valign="top">
				<th scope="row">
					<label for="newad[name]">Nombre<br /> (opcional)</label>
				</th>
				<td>
					<input type="text" value="" id="newad[name]" name="newad[name]" />
				</td>
			</tr>
			<tr valign="top">
				<th scope="row">
					<label for="newad[format]">Formato</label>
				</th>
				<td>
					<?=$this->getOptionsSelect($this->options['format'], 'newad[format]')?>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row">
					<label for="newad[location]">Ubicación</label>
				</th>
				<td>
					<?=$this->getOptionsSelect($this->options['location'], 'newad[location]')?>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row">
					<label for="newad[align]">Alineación</label>
				</th>
				<td>
					<?=$this->getOptionsSelect($this->options['align'], 'newad[align]')?>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row">
					<label for="newad[olderthan]">Publicación</label>
				</th>
				<td>
					<?=$this->getOptionsSelect($this->options['olderthan'], 'newad[olderthan]')?>
				</td>
			</tr>
			<tr valign="top">			
				<th scope="row">
					<label for="newad[before]">HTML Previo<br /> (opcional)</label>
				</th>
				<td>				
					<textarea id="newad[before]" name="newad[before]" cols="60" rows="4" style="width:90%;"></textarea>
				</td>
			</tr>
			<tr valign="top">			
				<th scope="row">				
					<label for="newad[after]">HTML Posterior<br /> (opcional)</label>
				</th>
				<td>				
					<textarea id="newad[after]" name="newad[after]" cols="60" rows="4" style="width:90%;"></textarea>
				</td>				
			</tr>			
		</tbody>
	</table>
	<p class="submit">
		<input type="submit" name="submit" value="<?php _e('Save Changes') ?>"  class="button-primary" />
	</p>
	</form>
	

</div><!--.wrap-->
<?php endif; //taran! ?>